package com.demo.pattern.single;

// 懒汉式，静态内部类
public class DemoTest7 {
    public static void main(String[] args) {
        System.out.println(Single7.getInstance() == Single7.getInstance());
    }
}

class Single7 {

    // 私有构造方法，外部不能new
    private Single7() {
    }

    // 静态内部类
    private static class SingleInstance {

        private final static Single7 instance = new Single7();
    }

    public static synchronized Single7 getInstance() {
        return SingleInstance.instance;
    }
}